package org.bbb.library1.product;

/*******************************************************************************
 * Copyright (c) 2007 Finalist IT Group B.V.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *    Rob Schellhorn - initial API and implementation
 *******************************************************************************/
//package com.finalist.rcp.internal.product;

import org.eclipse.jface.action.GroupMarker;
import org.eclipse.jface.action.IContributionItem;
import org.eclipse.jface.action.ICoolBarManager;
import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.action.IToolBarManager;
import org.eclipse.jface.action.MenuManager;
import org.eclipse.jface.action.Separator;
import org.eclipse.jface.action.ToolBarManager;
import org.eclipse.swt.SWT;
import org.eclipse.ui.IWorkbenchActionConstants;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.actions.ActionFactory;
import org.eclipse.ui.application.ActionBarAdvisor;
import org.eclipse.ui.application.IActionBarConfigurer;

/**
 * @author Rob Schellhorn
 */
public class DemoActionBarAdvisor extends ActionBarAdvisor {

   public DemoActionBarAdvisor(IActionBarConfigurer configurer) {
      super(configurer);
   }

   private IContributionItem createMenuEdit() {
      MenuManager menu = new MenuManager("&Edit", IWorkbenchActionConstants.M_EDIT);
      menu.add(getAction(ActionFactory.UNDO.getId()));
      menu.add(getAction(ActionFactory.REDO.getId()));
      menu.add(new Separator());
      menu.add(getAction(ActionFactory.CUT.getId()));
      menu.add(getAction(ActionFactory.COPY.getId()));
      menu.add(getAction(ActionFactory.PASTE.getId()));
      menu.add(new Separator());
      menu.add(new GroupMarker(IWorkbenchActionConstants.MB_ADDITIONS));
      menu.add(new Separator());
      menu.add(getAction(ActionFactory.DELETE.getId()));

      return menu;
   }

   private IContributionItem createMenuFile() {
      MenuManager menu = new MenuManager("&File", IWorkbenchActionConstants.M_FILE);
      menu.add(getAction(ActionFactory.CLOSE.getId()));
      menu.add(getAction(ActionFactory.CLOSE_ALL.getId()));
      menu.add(new Separator());
      menu.add(getAction(ActionFactory.SAVE.getId()));
      menu.add(getAction(ActionFactory.SAVE_ALL.getId()));
      menu.add(getAction(ActionFactory.SAVE_AS.getId()));
      menu.add(new Separator());
      menu.add(new GroupMarker(IWorkbenchActionConstants.MB_ADDITIONS));
      menu.add(new Separator());
      menu.add(getAction(ActionFactory.QUIT.getId()));

      return menu;
   }

   /*
    * @see org.eclipse.ui.application.ActionBarAdvisor#fillCoolBar(org.eclipse.jface.action.ICoolBarManager)
    */
   @Override
   protected void fillCoolBar(ICoolBarManager coolBar) {
      MenuManager menuManager = new MenuManager();
      menuManager.add(getAction(ActionFactory.LOCK_TOOL_BAR.getId()));

      coolBar.setContextMenuManager(menuManager);

      IToolBarManager mainToolBar = new ToolBarManager(SWT.FLAT | SWT.RIGHT);
      mainToolBar.add(getAction(ActionFactory.NEW_WIZARD_DROP_DOWN.getId()));
      mainToolBar.add(getAction(ActionFactory.SAVE.getId()));

      coolBar.add(mainToolBar);
   }

   /*
    * @see org.eclipse.ui.application.ActionBarAdvisor#fillMenuBar(org.eclipse.jface.action.IMenuManager)
    */
   @Override
   protected void fillMenuBar(IMenuManager menuBar) {
      menuBar.add(createMenuFile());
      menuBar.add(createMenuEdit());
      menuBar.add(new GroupMarker(IWorkbenchActionConstants.MB_ADDITIONS));
   }

   /*
    * @see org.eclipse.ui.application.ActionBarAdvisor#makeActions(org.eclipse.ui.IWorkbenchWindow)
    */
   @Override
   protected void makeActions(IWorkbenchWindow window) {
      register(ActionFactory.ABOUT.create(window));
      register(ActionFactory.CLOSE.create(window));
      register(ActionFactory.CLOSE_ALL.create(window));
      register(ActionFactory.COPY.create(window));
      register(ActionFactory.CUT.create(window));
      register(ActionFactory.DELETE.create(window));
      register(ActionFactory.HELP_CONTENTS.create(window));
      register(ActionFactory.HELP_SEARCH.create(window));
      register(ActionFactory.LOCK_TOOL_BAR.create(window));
      register(ActionFactory.NEW_WIZARD_DROP_DOWN.create(window));
      register(ActionFactory.PASTE.create(window));
      register(ActionFactory.QUIT.create(window));
      register(ActionFactory.REDO.create(window));
      register(ActionFactory.SAVE.create(window));
      register(ActionFactory.SAVE_ALL.create(window));
      register(ActionFactory.SAVE_AS.create(window));
      register(ActionFactory.UNDO.create(window));
   }
}
